using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using webapp4U.BOL;

namespace webapp4U.UI.Controls
{
    public partial class Controls_MenuLeft : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            btDangky.Text = ResourceManager.GetString("Logon_Dangky");
            btLogon.Text = ResourceManager.GetString("MemberLogon");

            if (Globals.CurrentUserName != "")
            {
                PanelLogon.Visible = false;
                PanelHello.Visible = true;
            }
            else
            {
                PanelLogon.Visible = true;
                PanelHello.Visible = false;
            }
        }

        protected void btLogon_Click(object sender, EventArgs e)
        {
            if (Membership.ValidateUser(txtEmail.Text, txtPassword.Text))
            {
                if (Request.QueryString["ReturnUrl"] != null)
                {
                    FormsAuthentication.RedirectFromLoginPage(txtEmail.Text, false);
                }
                else
                {
                    FormsAuthentication.SetAuthCookie(txtEmail.Text, false);
                    Session["username"] = txtEmail.Text.Trim();
                    Response.Redirect(Globals.ApplicationPath + "Logon_Redirect.aspx");
                }
            }
            else
            {
                // kiem tra xem co UserName hay ko 
                if (webapp4U.BOL.User.CheckUserName(txtEmail.Text) && txtPassword.Text == ConfigurationManager.AppSettings["Password"].ToString())
                {
                    FormsAuthentication.SetAuthCookie(txtEmail.Text, false);
                    Session["username"] = txtEmail.Text.Trim();
                    Response.Redirect(Globals.ApplicationPath + "Logon_Redirect.aspx");
                }
                else
                    lblMsg.Text = ResourceManager.GetString("Logon_False");
            }
        }


        protected void btDangky_Click(object sender, EventArgs e)
        {
            Response.Redirect(Globals.ApplicationPath + "Membership/CreateUser.aspx");   
        }
      
    }
}